﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 易容酒店管理系统
{
    public partial class Money : Form
    {
        public Money()
        {
            InitializeComponent();
        }
        public int money = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            string Sql = "";
            string Setting = "";
            int num = Convert.ToInt32(labMoney.Text);
            int Money = 0;
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            using (SqlConnection con = new SqlConnection(Link))
            {
                string SqlMoney = "select Money from Goods where GoodsType='" + comboBox1.Text + "'";
                using (SqlCommand cmd = new SqlCommand(SqlMoney,con))
                {
                    con.Open();
                    Money = Convert.ToInt32(cmd.ExecuteScalar());
                    con.Close();
                }
                num +=Convert.ToInt32( Money * numericUpDown1.Value);
                Sql = "update Guest_Room_Number set InMoney='" + num + "',InNumber='" + comboBox1.Text + "*" + numericUpDown1.Value.ToString() + "' where RoomID='" + Method.RoomID + "';";
                using (SqlCommand cmd = new SqlCommand(Sql, con))
                {
                    con.Open();
                    int judge = cmd.ExecuteNonQuery();
                    if (judge > 0)
                    {
                        //
                    }
                    con.Close();
                }
                if (radioButton1.Checked)
                {
                    Setting = "update GuestInfo set setting='已打扫' where RoomID='" + Method.RoomID + "'";
                }
                else
                {
                    Setting = "update GuestInfo set setting='未打扫' where RoomID='" + Method.RoomID + "'";
                }
                using (SqlCommand cmd = new SqlCommand(Setting, con))
                {
                    con.Open();
                    int judge = cmd.ExecuteNonQuery();
                    if (judge > 0)
                    {
                        //
                    }
                }
            }
            Lookup();
        }

        private void Money_Load(object sender, EventArgs e)
        {
            Lookup();
        }

        private void Lookup()
        {

            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            SqlConnection con = new SqlConnection(Link);
            string Sql = "select * from Goods;";
            SqlDataAdapter Add = new SqlDataAdapter(Sql, con);
            DataSet set = new DataSet();
            Add.Fill(set, "Goods");
            DataTable table = set.Tables["Goods"];
            comboBox1.DisplayMember = "GoodsType";
            comboBox1.DataSource = set.Tables["Goods"];


            string setting = "";
            using (SqlConnection con2 = new SqlConnection(Link))
            {
                string Sql2 = "select setting from GuestInfo where RoomID='" + Method.RoomID + "';";
                using (SqlCommand cmd = new SqlCommand(Sql2, con2))
                {
                    con2.Open();
                    setting = cmd.ExecuteScalar().ToString();
                }
            }
            if (setting == "已打扫")
            {
                radioButton1.Checked = true;
            }
            else
            {
                radioButton2.Checked = false;
            }
            string Sql3 = "select InMoney,InNumber from Guest_Room_Number where RoomID='" + Method.RoomID + "';";
            using (SqlCommand cmd2 = new SqlCommand(Sql3, con))
            {

                con.Open();
                SqlDataReader red = cmd2.ExecuteReader();
                if (red.HasRows)
                {
                    red.Read();
                    money = Convert.ToInt32(red[0]);
                }
                labMoney.Text = money.ToString();
            }
        }

        private void picColse_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}